import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']    will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if true, the page will no be cached(default is false)
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
export const constantRouterMap = [
    // {
    //     path: '/redirect',
    //     component: Layout,
    //     hidden: true,
    //     children: [
    //         {
    //             path: '/redirect/:path*',
    //             component: () => import('@/views/redirect/index')
    //         }
    //     ]
    // },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/authredirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/errorPage/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/errorPage/401'),
        hidden: true
    }
];

export default new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
});


export const asyncRouterMap = [
    {
        path: '',
        component: Layout,
        redirect: 'admin',
        children: [
            //  管理员
            {
                path: 'admin',
                name: 'admin',
                redirect: 'admin/adminlist',
                pPath: '',
                meta: { title: '系统管理', icon: 'dashboard', noCache: true }
            },
            //  管理员列表
            {
                path: 'admin/adminlist',
                component: () => import('@/views/admin/admin/list'),
                name: 'adminList',
                pPath: 'admin',
                meta: { title: '管理员列表', icon: 'dashboard', noCache: true }
            },
            {
                path: 'admin/adminlist/add',
                component: () => import('@/views/admin/admin/add'),
                name: 'adminListAdd',
                pPath: 'admin/adminlist',
                meta: { title: '添加管理员', icon: 'dashboard', noCache: true, type: 'button' }
            },
            //  角色管理
            {
                path: 'admin/rolelist',
                component: () => import('@/views/admin/role/list'),
                name: 'roleList',
                pPath: 'admin',
                meta: { title: '角色列表', icon: 'dashboard', noCache: true }
            },
            {
                path: 'admin/rolelist/add',
                component: () => import('@/views/admin/role/add'),
                name: 'roleListAdd',
                pPath: 'admin/rolelist',
                meta: { title: '添加角色', icon: 'dashboard', noCache: true, type: 'button' }
            },
            //  卡列表管理
            {
                path: 'cardlist',
                component: () => import('@/views/card/list'),
                name: 'cardList',
                pPath: '',
                meta: { title: '用户卡管理', icon: 'dashboard', noCache: true }
            },
            {
                path: 'cardlist/add',
                component: () => import('@/views/card/add'),
                name: 'cardListAdd',
                pPath: 'cardlist',
                meta: { title: '添加用户卡', icon: 'dashboard', noCache: true, type: 'button' }
            },
            //  系统管理
            {
                path: 'system',
                name: 'system',
                redirect: 'system/menulist',
                pPath: '',
                meta: { title: '系统管理', icon: 'dashboard', noCache: true }
            },
            {
                path: 'system/menulist',
                component: () => import('@/views/system/menu/list'),
                name: 'menuList',
                pPath: 'system',
                meta: { title: '菜单管理', icon: 'dashboard', noCache: true }
            },
            //  会员管理
            {
                path: 'user',
                component: () => import('@/views/user/list'),
                name: 'userList',
                pPath: '',
                meta: { title: '会员管理', icon: 'dashboard', noCache: true }
            },
            {
                path: 'user/add',
                component: () => import('@/views/user/add'),
                name: 'userListAdd',
                pPath: 'userlist',
                meta: { title: '添加用户', icon: 'dashboard', noCache: true, type: 'button' }
            }
        ]
    },

    // { path: '*', redirect: '/404', hidden: true }
]
